#include "cacheTest.h"
template<typename T>
void alloc(T** & c,int size){
    c = new T*[size];
    for(int h = 0;h<size;h++){
        c[h] = new T[size];
    }
}
void cacheTest(){
    long t1 = clock();
    const int y = 1000;
    int** a;
    int** b;
    int** c;
    alloc<int>(a,y);
    alloc<int>(b,y);
    alloc<int>(c,y);
    for(int i = 0;i<y;i++){
        for(int j = 0;j<y;j++){
            for(int k = 0;k<y;k++){
                a[i][j] += b[i][k]*c[k][j];//c可能存在很多二级（或某级）缓存未命中的事件
            }
        }
    }
    long t2 = clock();
    cout<<t2-t1<<endl;
    alloc<int>(a,y);
    alloc<int>(b,y);
    alloc<int>(c,y);
    long t3 = clock();
    for(int i = 0;i<y;i++){
        for(int k = 0;k<y;k++){
            for(int j = 0;j<y;j++){
                a[i][j] += b[i][k]*c[k][j];//不存在上述情况
            }
        }
    }
    cout<<clock()-t3<<endl;
}